package com.jz.netthings.appengine.baseData;

import java.io.Serializable;
import java.util.Date;

/**
 * 采浆设备
 */
public class MachineData implements Serializable,Comparable<MachineData> {

    public static final int FREE = 1;
    public static final int OCCUPY = 2;
    public static final int SUSPEND = 3;
    public static final int DISABLE = 4;
    public static final int BUSY = 5;

    //设备标识
    private String id;
    //设备代码
    private String code;
    //设备能否联网
    private boolean network;

    //护士
    private String nurseCode;
    private String nurseName;

    //设备当前状态信息
    private int runStatus;
    private String statusInfo;
    //设备当前采浆重量
    private int weight;
    //设备是否在线
    private boolean online;

    //设备分配时间
    private Date allotTime;

    //设备开始采浆时间
    private Date collectingTime;

    //设备预计完成等待时间
    private long waitTime;

    //设备暂停使用
    private boolean suspend;

    //当前在这个机器上的浆员的ID
    private String gjzId;

    public int getStatus() {
        if (suspend) {
            return SUSPEND;
        }
        if (!online) {
            return DISABLE;
        }
        if (allotTime != null) {
            return OCCUPY;
        }
        if (collectingTime != null) {
            return OCCUPY;
        }
        if (((runStatus >= 3) && (runStatus < 7)) || (runStatus >= 12)) {
            return FREE;
        }
        return BUSY;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getNurseCode() {
        return nurseCode;
    }

    public void setNurseCode(String nurseCode) {
        this.nurseCode = nurseCode;
    }

    public String getNurseName() {
        return nurseName;
    }

    public void setNurseName(String nurseName) {
        this.nurseName = nurseName;
    }

    public boolean isNetwork() {
        return network;
    }

    public void setNetwork(boolean network) {
        this.network = network;
    }

    public boolean isOnline() {
        return online;
    }

    public void setOnline(boolean online) {
        this.online = online;
    }

    public String getStatusInfo() {
        return statusInfo;
    }

    public void setStatusInfo(String statusInfo) {
        this.statusInfo = statusInfo;
    }

    public int getWeight() {
        return weight;
    }

    public void setWeight(int weight) {
        this.weight = weight;
    }

    public Date getAllotTime() {
        return allotTime;
    }

    public void setAllotTime(Date allotTime) {
        this.allotTime = allotTime;
    }

    public Date getCollectingTime() {
        return collectingTime;
    }

    public void setCollectingTime(Date collectingTime) {
        this.collectingTime = collectingTime;
    }

    public long getWaitTime() {
        return waitTime;
    }

    public void setWaitTime(long waitTime) {
        this.waitTime = waitTime;
    }

    public boolean isSuspend() {
        return suspend;
    }

    public void setSuspend(boolean suspend) {
        this.suspend = suspend;
    }

    public int getRunStatus() {
        return runStatus;
    }

    public void setRunStatus(int runStatus) {
        this.runStatus = runStatus;
    }

    public void doFree() {
        allotTime = null;
        collectingTime = null;
        weight = 0;
    }

    public void doOccupy() {
        setAllotTime(new Date(System.currentTimeMillis()));
    }

    public void doCollecting() {
        setCollectingTime(new Date(System.currentTimeMillis()));
    }

    public void doSuspend() {
        setSuspend(true);
    }

    public void doResume() {
        setSuspend(false);
    }

    public void doCopyToOther(MachineData other) {
        other.setNurseCode(nurseCode);
        other.setNurseName(nurseName);

        other.setRunStatus(runStatus);
        other.setStatusInfo(statusInfo);
        other.setWeight(weight);
        other.setOnline(online);
        other.setAllotTime(allotTime);
        other.setCollectingTime(collectingTime);
        other.setWaitTime(waitTime);
        other.setSuspend(suspend);
        other.setGjzId(gjzId);
    }

    public String getGjzId() {
        return gjzId;
    }

    public void setGjzId(String gjzId) {
        this.gjzId = gjzId;
    }

    @Override
    public String toString() {
        return "MachineData [id=" + id + ", code=" + code + ", network=" + network + ", nurseCode=" + nurseCode
                + ", nurseName=" + nurseName + ", runStatus=" + runStatus + ", statusInfo=" + statusInfo + ", weight="
                + weight + ", online=" + online + ", allotTime=" + allotTime + ", collectingTime=" + collectingTime
                + ", waitTime=" + waitTime + ", suspend=" + suspend + ", gjzId=" + gjzId + "]";
    }

    @Override
    public int compareTo(MachineData data) {
        int result = 0;
        try{
            result = Integer.valueOf(this.getId()) - Integer.valueOf(data.getId());
        }catch (Exception e){
            e.printStackTrace();
        }

        return result;
    }
}
